import maya.cmds as cmds

if (not cmds.objExists("screwMountShader")):
    screwMountShader = cmds.shadingNode('lambert', asShader=True,name="screwMountShader");
cmds.setAttr("screwMountShader.color",0.960784,0.0753556,0.0753556,type="double3");

wallThickness = 0.7;
baseThickness = 1.4;
boardBuffer = 1.0;#distance between board and box
mwSideLength = 40.0 + boardBuffer;
enclosureHeight = 30.0;
mountHoleRadius = 3.0/2;
mountHoleThickness = 1.0/2;
mountOuterRadius = mountHoleRadius + mountHoleThickness;
mountHoleDistance = 35;
strapWidth = 15;
strapHoleHeight = 2.3;
screwMountHeight = strapHoleHeight + wallThickness + 1.5;

def createScrewMount( x, z, object):
    aMount = cmds.polyPipe(r=mountOuterRadius,h=screwMountHeight*2,t=mountHoleThickness)#polypipe bug, where height is created at half height. :(
    cmds.move(x,(screwMountHeight/2.0 + baseThickness),z);
    cmds.select(aMount[0]);
    cmds.hyperShade(a="screwMountShader");
    cmds.select(aMount[0],object[0]);
    return cmds.polyBoolOp(op=1);

def createStrap(object):

    strapInner = cmds.polyCube(w=strapWidth, h=strapHoleHeight,d=mwSideLength*2);
    cmds.move(0,strapHoleHeight/2.0 + baseThickness,0);  
    cmds.select(object[0],strapInner[0]);
    object = cmds.polyBoolOp(op=2);
 
    strapInner1 = cmds.polyCube(w=wallThickness, h=strapHoleHeight,d=mwSideLength);
    cmds.move(-strapWidth/2.0-wallThickness/2.0,strapHoleHeight/2.0 + baseThickness,0);  
    cmds.select(object[0],strapInner1[0]);
    object = cmds.polyBoolOp(op=1);
# #     
    strapInner2 = cmds.polyCube(w=wallThickness, h=strapHoleHeight,d=mwSideLength);
    cmds.move(strapWidth/2.0+wallThickness/2.0,strapHoleHeight/2.0 + baseThickness,0);  
    cmds.select(object[0],strapInner2[0]);
    return cmds.polyBoolOp(op=1);    

cmds.SelectAll();
cmds.Delete();

enclosure = cmds.polyCube(w=(mwSideLength+wallThickness*2), h=(enclosureHeight),d=(mwSideLength+wallThickness*2));
inside = cmds.polyCube(w=(mwSideLength), h=enclosureHeight,d=(mwSideLength));
cmds.select(inside[0],r=True);
cmds.move(0,baseThickness, 0);
cmds.select(enclosure[0],inside[0],r=True);
enclosure = cmds.polyBoolOp(op=2);

cmds.move(0,(enclosureHeight/2), 0);


cmds.select(enclosure[0],r=True);



enclosure = createScrewMount(mountHoleDistance/2,mountHoleDistance/2,enclosure);
enclosure = createScrewMount(mountHoleDistance/2,-mountHoleDistance/2,enclosure);
enclosure = createScrewMount(-mountHoleDistance/2,mountHoleDistance/2,enclosure);
enclosure = createScrewMount(-mountHoleDistance/2,-mountHoleDistance/2,enclosure);
enclosure = createStrap(enclosure);

cmds.select(enclosure);
cmds.rotate('90deg',0,0);


